using System;
using System.Collections;
using System.Net;
using System.Net.Sockets;
using Oracle.ManagedDataAccess.Client;
using OracleInternal.Common;

namespace OracleInternal.ServiceObjects
{
	internal class OracleDependencyImpl
	{
		internal static int m_portForlistening = -1;

		internal static string s_machineAddress;

		internal bool m_bIsRegistered;

		internal long m_clientRegistrationId;

		internal int m_RegIdFromServer;

		internal bool m_bIsEnabled;

		internal object m_syncList = new object();

		internal ArrayList m_queryIDList = new ArrayList();

		internal bool m_bIsNotifiedOnce;

		internal bool m_bIsPersistent;

		internal long m_timeout;

		internal bool m_bExcludeRowId;

		internal bool m_bIncludeRowId;

		internal bool m_bQueryBasedNTFN = true;

		internal ArrayList m_regList = ArrayList.Synchronized(new ArrayList());

		internal static bool m_bIsAddressConfigured = false;

		internal string m_clientId;

		internal string m_listenerAddress;

		internal string m_guid;

		internal OracleDependencyImpl(bool isNotifiedOnce, long timeout, bool isPersistent)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleDependencyImpl, OracleTraceFuncName.ctor);
			}
			m_bIsRegistered = false;
			m_bIsNotifiedOnce = isNotifiedOnce;
			m_bIsPersistent = isPersistent;
			m_timeout = timeout;
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleDependencyImpl, OracleTraceFuncName.ctor);
			}
		}

		internal static string GetMachineAddress()
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleDependencyImpl, OracleTraceFuncName.GetMachineAddress);
			}
			string str = string.Empty;
			string text = string.Empty;
			try
			{
				str = "program";
				if (!string.IsNullOrEmpty(s_machineAddress))
				{
					text = s_machineAddress;
					return text;
				}
				str = "config";
				if (!string.IsNullOrEmpty(ConfigBaseClass.m_DBNotificationAddress))
				{
					m_bIsAddressConfigured = true;
					text = ConfigBaseClass.m_DBNotificationAddress;
					return text;
				}
				str = ".NET";
				text = GetAddress(Dns.GetHostName());
				return text;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleDependencyImpl, OracleTraceFuncName.GetMachineAddress, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, OracleTraceTag.SvcObj, OracleTraceClassName.OracleDependencyImpl, OracleTraceFuncName.GetMachineAddress, "Address (" + str + ")=" + text);
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleDependencyImpl, OracleTraceFuncName.GetMachineAddress);
				}
			}
		}

		internal static string GetAddress(string hostName)
		{
			string hostName2 = Dns.GetHostName();
			if (string.IsNullOrEmpty(hostName))
			{
				hostName = hostName2;
			}
			else if (hostName.Contains(":"))
			{
				if (hostName.StartsWith("["))
				{
					return hostName;
				}
				return "[" + hostName.ToString() + "]";
			}
			IPAddress iPAddress = null;
			IPAddress iPAddress2 = null;
			IPAddress[] hostAddresses = Dns.GetHostAddresses(hostName);
			for (int i = 0; i < hostAddresses.Length; i++)
			{
				iPAddress2 = hostAddresses[i];
				if (iPAddress2.AddressFamily == AddressFamily.InterNetwork)
				{
					return iPAddress2.ToString();
				}
				if (iPAddress == null && iPAddress2.AddressFamily == AddressFamily.InterNetworkV6)
				{
					iPAddress = iPAddress2;
				}
			}
			return "[" + iPAddress.ToString() + "]";
		}

		internal void SetRegisterInfo(bool isNotifiedOnce, bool isPersistent, long timeout)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleDependencyImpl, OracleTraceFuncName.SetRegisterInfo);
			}
			m_bIsNotifiedOnce = isNotifiedOnce;
			m_bIsPersistent = isPersistent;
			m_timeout = timeout;
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleDependencyImpl, OracleTraceFuncName.SetRegisterInfo);
			}
		}
	}
}
